﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QLChoDiaOc.Process
{
    class GetID
    {
        QLChoDiaOcEntities m_entities = new QLChoDiaOcEntities();
        SelectInfo m_selectInfo = new SelectInfo();

        public String GenerateMaKH()
        {
            List<String> listMaKH = m_selectInfo.SelectAllMaKH();
            String generatedMaKH;
            do
            {
                generatedMaKH = "";

                var chars = "FGDF8G7S5D7FWHJRTGEWO8652958645869SG6F9D8G75XC7V46X436D3F649JGTGE46DF7HJ3H52GHMBVUHJXVBSDIY";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaKH += "KH" + result;
            } while (listMaKH.Contains(generatedMaKH));
            return generatedMaKH;
        }

        public String GenerateMaDiaOc()
        {
            List<String> listMaDiaOc = m_selectInfo.SelectAllMaDiaOc();
            String generatedMaDiaOc;
            do
            {
                generatedMaDiaOc = "";

                var chars = "ETYUI98JGFU647FWHJRTGEWO8652958G75XC7V46XK3F66LKJF9D84HJ3H5X45869HJSG6432GHMBVUHJ6DVBSDI43Y";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaDiaOc += "DO" + result;
            } while (listMaDiaOc.Contains(generatedMaDiaOc));
            return generatedMaDiaOc;
        }

        public String GenerateMaPhieuDangKy()
        {
            List<String> listMaPhieuDangKy = m_selectInfo.SelectAllMaPhieuDangKy();
            String generatedMaPhieuDangKy;
            do
            {
                generatedMaPhieuDangKy = "";

                var chars = "U64958G75XC7FWEWLI98JGF2K3F6DIG43VO86527H4V6695JSXJX4J58GKJF9D86HB3Y4ETYUDS6RTHGHMBVUH64HJ3";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaPhieuDangKy += "PD" + result;
            } while (listMaPhieuDangKy.Contains(generatedMaPhieuDangKy));
            return generatedMaPhieuDangKy;
        }

        public String GenerateMaQCBao()
        {
            List<String> listMaQCBao = m_selectInfo.SelectAllMaQCBao();
            String generatedMaQCBao;
            do
            {
                generatedMaQCBao = "";

                var chars = "HGHMBVUH6C7FWEWLI98JGF2IG43VF4VDTVGDS6RTHFX4J86527H4HJ6544TYUB3Y4EOF9FX4J86527HD86U6495875X";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaQCBao += "QB" + result;
            } while (listMaQCBao.Contains(generatedMaQCBao));
            return generatedMaQCBao;
        }

        public String GenerateMaQCBang()
        {
            List<String> listMaQCBang = m_selectInfo.SelectAllMaQCBang();
            String generatedMaQCBang;
            do
            {
                generatedMaQCBang = "";

                var chars = "WLI98JGF843VX4UB3Y4EHV6R2IUH7HD8J9FX4H6GF44TY6J27H495J865GDSXC786U64THFF4VDTOFWE52GH65MBV75";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaQCBang += "QG" + result;
            } while (listMaQCBang.Contains(generatedMaQCBang));
            return generatedMaQCBang;
        }

        public String GenerateMaQCToBuom()
        {
            List<String> listMaQCToBuom = m_selectInfo.SelectAllMaQCToBuom();
            String generatedMaQCToBuom;
            do
            {
                generatedMaQCToBuom = "";

                var chars = "52GH65MBV75F45G6RVX8J9JGF843WLI988UB3Y4EHVFF4H495J866U64THDSXC72IUH7HDX4H6GFVDTOFWE44TY6J27";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaQCToBuom += "QT" + result;
            } while (listMaQCToBuom.Contains(generatedMaQCToBuom));
            return generatedMaQCToBuom;
        }

        public String GenerateMaPhieuThu()
        {
            List<String> listMaPhieuThu = m_selectInfo.SelectAllMaPhieuThu();
            String generatedMaPhieuThu;
            do
            {
                generatedMaPhieuThu = "";

                var chars = "GHEHH45I65MI72FGFG6VB4H6UB3Y4SXCF4H49JGDXE44TY6J2752R75F3WU64THD7VFW95J866988UHLF84VDTOVX8J";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaPhieuThu += "PT" + result;
            } while (listMaPhieuThu.Contains(generatedMaPhieuThu));
            return generatedMaPhieuThu;
        }

        public String GenerateMaLoaiDiaOc()
        {
            List<String> listMaLoaiDiaOc = m_selectInfo.SelectAllMaLoaiDiaOc();
            String generatedMaLoaiDiaOc;
            do
            {
                generatedMaLoaiDiaOc = "";

                var chars = "F4HFGFG6VB4H6UB3Y4S88UHL6J25F84VDT9GDXE44TYJ867VFWHH45I65M698J49J75GHEOVXXC2R75F3WU64THDI72";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaLoaiDiaOc += "LD" + result;
            } while (listMaLoaiDiaOc.Contains(generatedMaLoaiDiaOc));
            return generatedMaLoaiDiaOc;
        }

        public String GenerateMaLoaiBang()
        {
            List<String> listMaLoaiBang = m_selectInfo.SelectAllMaLoaiBang();
            String generatedMaLoaiBang;
            do
            {
                generatedMaLoaiBang = "";

                var chars = "T9GDXE44TYJ8L6J25F84VD49JWUB3Y4S88UH72FGFG6VF3B4H6V75WHH45I65M698JU64THDI67F4HXXC2R75FGHEOV";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaLoaiBang += "LB" + result;
            } while (listMaLoaiBang.Contains(generatedMaLoaiBang));
            return generatedMaLoaiBang;
        }

        public String GenerateMaToBao()
        {
            List<String> listMaToBao = m_selectInfo.SelectAllMaToBao();
            String generatedMaToBao;
            do
            {
                generatedMaToBao = "";

                var chars = "49JWGDXE44TYB3Y4S88UH724698JU684VD75FGHEOVUGFG4F7F4HXXC2R5ML6J25FJ85I6V75WHHTHDI66VF3B4H6T9";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaToBao += "TB" + result;
            } while (listMaToBao.Contains(generatedMaToBao));
            return generatedMaToBao;
        }

        public String GenerateMaNhanVien()
        {
            List<String> listMaNhanVien = m_selectInfo.SelectAllMaNhanVien();
            String generatedMaNhanVien;
            do
            {
                generatedMaNhanVien = "";

                var chars = "HEOVUGFG4F7B3Y4S883BJWGDXE4V75WHHR5TY4F4HXXC4J85I64H6T9THDI69UH724698JU684VD75FG2ML6J25F6VF";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaNhanVien += "NV" + result;
            } while (listMaNhanVien.Contains(generatedMaNhanVien));
            return generatedMaNhanVien;
        }

        public String GenerateMaLoaiNhanVien()
        {
            List<String> listMaLoaiNhanVien = m_selectInfo.SelectAllMaLoaiNhanVien();
            String generatedMaLoaiNhanVien;
            do
            {
                generatedMaLoaiNhanVien = "";

                var chars = "GDXE4V75WHHR5TY4T9F4HXXC4J8HFG2ML6JB3Y4S883BEOVUGFG4F772469THDI69UH25F6VF8JU684VD75JW5I64H6";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 2)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaLoaiNhanVien += "LNV" + result;
            } while (listMaLoaiNhanVien.Contains(generatedMaLoaiNhanVien));
            return generatedMaLoaiNhanVien;
        }
    }
}
